package com.zdy.demo;

/**
 * Created by 逸足天涯
 * on 3/8/2020.
 */
//出现线程并发问题
public class TestThread4 implements Runnable{

    private int tickNums = 10;

    @Override
    public void run() {
            while(true){
                if(tickNums <= 0){break;}
                try {
                    Thread.sleep(200);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(Thread.currentThread().getName() + "-->拿到了第" + tickNums-- +"票");
            }


    }

    public static void main(String[] args) {
        System.out.println("创建线程");
        TestThread4 tickets = new TestThread4();
        new Thread(tickets,"小明").start();
        new Thread(tickets,"老师").start();
        new Thread(tickets,"黄牛党").start();
    }
}
